import React from "./core/react.js";
import ReactDom from "./core/react-dom.js";
import App from "./src/app.jsx";

const nodesQueue = [];
function crateNode(node) {
  const isFunctionNode = typeof node.type === "function";
  const isHTMLTextNode = typeof node.type === "TEXT_ELEMENT";
  const isHTMLTagNode = typeof node.type === "string";
  const isText = typeof node === "string" || typeof node === "number";

  if (isFunctionNode) {
    const { children, ...args } = node.props;
    node.props.children = [node.type(args)];
  } else if (isHTMLTextNode) {
  } else if (isHTMLTagNode) {
  } else if (isText) {
    node = { type: "TEXT_ELEMENT", props: { nodeValue: node, children: [] } };
  }

  nodesQueue.push(node);

  const hasChildren = node.props.children?.length > 0;
  if (hasChildren) {
    const children = node.props.children;
    children.forEach((child) => {
      const node = crateNode(child);
    });
  }
}

crateNode(<App n={1}></App>);
console.log("🚀 ~ head:", nodesQueue);

ReactDom.createRoot(document.querySelector("#root")).render(<App n={1}></App>);
